<?php
error_reporting(E_ALL);

//spl_autoload_register('apiAutoload');
//
//function apiAutoload($classname) {
//    if (preg_match('/[a-zA-Z]+Controller$/', $classname)) {
//        include __DIR__ . '/controllers/' . $classname . '.php';
//        return true;
//    } elseif (preg_match('/[a-zA-Z]+Model$/', $classname)) {
//        include __DIR__ . '/models/' . $classname . '.php';
//        return true;
//    } elseif (preg_match('/[a-zA-Z]+View$/', $classname)) {
//        include __DIR__ . '/views/' . $classname . '.php';
//        return true;
//    }
//}

include 'QRController.php';
include 'Request.php';
include 'functions.php';


$request = new Request();

if(isset($request->url_elements[1]) && strtolower($request->url_elements[1]) === "qr"){
    $controller = new QRController(getcwd());
    
    if(strtolower($request->verb) === "get"){
        echo $controller->getAction($request);
    }
    else if(strtolower($request->verb) === "post"){
        echo $controller->postAction($request);
    }
}



//try{
// route the request to the right place
//$controller_name = $request->url_elements[1]."Controller";
//if (class_exists($controller_name)) {
//    echo $controller_name;
//    $controller = new $controller_name();
//    $action_name = strtolower($request->verb) . 'Action';
//    $result = $controller->$action_name();
//    print_r($result);
//} else {
//    print_r($request->url_elements);
//}


//$view_name = ucfirst($request->format) . 'View';
//if (class_exists($view_name)) {
//    $view = new $view_name();
//    $view->render($result);
//}


//nachforschungen
//echo "<h1>Server Variabeln</h1>";
//echo "<p>";
//echo "PATH_INFO: ".$_SERVER['PATH_INFO']."<br/>";
//echo "REQUEST_METHOD: ".$_SERVER['REQUEST_METHOD']."<br/>";
//echo "QUERY_STRING: ".$_SERVER['QUERY_STRING']."<br/>";
//echo "CONTENT_TYPE: ".$_SERVER['CONTENT_TYPE']."<br/>";
//echo "</p>";
//
//echo "<h1>Request</h1>";
//echo "<p>";
//echo $request->url_elements[1];
//echo "</p>";



?>
